import Vue from 'vue'
import Vuex from "vuex";
// 引入插件
import createPersistedState from "vuex-persistedstate";
import user from './module/user.js'
Vue.use(Vuex);

const store = new Vuex.Store({
	modules: {
		user
	},
	/* vuex数据持久化配置 */
	plugins: [
		createPersistedState({
			// 存储方式：localStorage、sessionStorage、cookies
			storage: { // 存储方式定义  
				getItem: (key) => uni.getStorageSync(key), // 获取  
				setItem: (key, value) => uni.setStorageSync(key, value), // 存储  
				removeItem: (key) => uni.removeStorageSync(key) // 删除  
			},
			// 存储的 key 的key值
			key: "storemsg",
			paths: ['user']
		})
	]
});
// 重置store
export function resetStore() {
	store.replaceState(createStore(options).state)
}
export default store;
